
var FwdAssistant = Class.create(AbstractModule, {

setupWidgets: function() {

		//About
		this.controller.setupWidget(Mojo.Menu.appMenu, {
			omitDefaultItems: true
		}, {
			visible: true,
			items: [
      		Mojo.Menu.editItem,
			{ label: "Disclaimer", command: "do-disclaimer" },					
				{ label: "License", command: "do-license" },
				{ label: "Help", command: "do-help" }
			]
		});

	this.toggleunit =
	{
		modelProperty: 'togglestate',
		trueLabel: 'SI',
	falseLabel: 'US'
	};
	this.togglemodel = {
		togglestate: true
	};
	this.controller.setupWidget("unitField", this.toggleunit, this.togglemodel);
	this.controller.listen("unitField", Mojo.Event.propertyChanged, this.unitChanged.bindAsEventListener(this));

		this.controller.setupWidget("sex", {
			label: "Sex",
			choices: [
				{ label: "Male", value: 1},
				{ label: "Female", value: 0}
			]
		}, this.sexModel = {
			value: 1
		});
	
		this.controller.setupWidget("weightField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {value: weight});
	
			

	this.controller.setupWidget("pnaField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {value: sodium});
	
	
		this.controller.setupWidget("dnaField", {
		charsAllow: isValidFPNumber,
		modifierState: Mojo.Widget.numLock
	}, {value: 140});
	

},


unitChanged: function() {
//change unit display in bmi scene
var unitchoice = this.togglemodel.togglestate;

if (!unitchoice){
$("weightUnit").update("<span class=\"si\">(lbs)</span>");
$("pnaUnit").update("<span class=\"si\">(mEq/L)</span>");
$("dnaUnit").update("<span class=\"si\">(mEq/L)</span>");
}

if (unitchoice){
$("weightUnit").update("<span class=\"si\">(kg)</span>");
$("pnaUnit").update("<span class=\"si\">(&mu;mol/l)</span>");
$("dnaUnit").update("<span class=\"si\">(&mu;mol/l)</span>");
}
},

calculate: function() {

var result = fwdcalc(this.togglemodel.togglestate,this.sexModel.value,parseInt($("weightField").mojo.getValue()),parseInt($("pnaField").mojo.getValue()),parseInt($("dnaField").mojo.getValue()));
weight=result.weight;
sodium=result.sodium;

if (isNaN(result.fwd)){
return errormsg;
}
else {
return "The Free Water Deficit is "+ result.fwd +" L" ;
}
}
});



